//
//  HeaderView.m
//  licai
//
//  Created by apple on 15/11/16.
//  Copyright © 2015年 Boye. All rights reserved.
//

#import "ByMineHeaderView.h"

//#import "ByLoginVC.h"           // 登录
#import "ByMineInfoVC.h"          // 资料
@implementation ByMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        [self _initViews];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgTap)];
        [self addGestureRecognizer:tap];
    }
    
    return self;
    
}

#pragma mark -- 初始化子视图
- (void)_initViews {
    [self _initBgImgView];
    [self _initIconImgView];
    [self _initLabel];
//    [self _initTagIcon];
}
- (void)_initBgImgView {
    self.bgImgView = [[UIImageView alloc] initWithFrame:self.bounds];
//    self.bgImgView.image = [UIImage imageNamed:@"mine_bg"];
    self.bgImgView.image = [UIImage imageWithColor:HTB_THEME_COLOR];
    [self addSubview:self.bgImgView];
    
    UIImageView *indorView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
//    indorView.image = [UIImage imageNamed:@"mine_jiantou"];
    indorView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.bgImgView addSubview:indorView];
    indorView.y = self.height / 2 + 20;
    indorView.right = self.width - 20;
    
}
- (void)_initIconImgView {
    self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
    self.iconImgView.left = self.width / 4;
    self.iconImgView.y = self.height / 2 + 20;
    self.iconImgView.userInteractionEnabled = YES;
//    self.iconImgView.backgroundColor = [UIColor whiteColor];
    self.iconImgView.image = DEFAULT_HEAD;
    [self addSubview:self.iconImgView];
    self.iconImgView.layer.cornerRadius = self.iconImgView.width / 2;
    self.iconImgView.layer.masksToBounds = YES;
    
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconTap:)];
//    [self.iconImgView addGestureRecognizer:tap];
}
- (void)_initLabel {
    self.nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.right + 20, 0, self.width - 40 - (self.iconImgView.right + 20), 20)];
    self.nickLabel.font = FONT(14);
    self.nickLabel.textAlignment = NSTextAlignmentLeft;
    self.nickLabel.textColor = [UIColor whiteColor];
    self.nickLabel.text = @"任性不认命";
    [self addSubview:self.nickLabel];
    
    self.mobileLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nickLabel.left, 0, self.nickLabel.width, 20)];
    self.mobileLabel.font = FONT(14);
    self.mobileLabel.textAlignment = NSTextAlignmentLeft;
    self.mobileLabel.textColor = [UIColor whiteColor];
    self.mobileLabel.text = @"13157396112";
    [self addSubview:self.mobileLabel];
    
    CGFloat margin = 15;
    CGFloat remain = (self.iconImgView.height - self.nickLabel.height - self.mobileLabel.height - margin) / 2;
    self.nickLabel.top = self.iconImgView.top + remain;
    self.mobileLabel.top = self.nickLabel.bottom + margin;
}
//- (void)_initTagIcon {
//    self.tagIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64 + 10, 25 * 2, 25)];
//    self.tagIcon.image = DEFAULT_HEAD;
//    [self addSubview:self.tagIcon];
//}


#pragma mark -- 点击事件
//- (void)iconTap:(UITapGestureRecognizer *)tap {
//    
//    NSLog(@"icon");
//}
- (void)bgTap {
    ByBaseVC *superVC = (ByBaseVC *)self.viewController;
//    if (BY_USER == nil) {
//        ByLoginVC *vc = [[ByLoginVC alloc] init];
//        ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:vc];
//        [superVC presentViewController:navi animated:YES completion:nil];
//        return;
//    }
    ByMineInfoVC *vc = [[ByMineInfoVC alloc] init];
    [superVC by_normalPush:vc hasNavi:YES];
}



#pragma mark -- 其他方法
//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//    UIView *view = [super hitTest:point withEvent:event];
//    
//    point = [self convertPoint:point toView:self.iconImgView];
//    if ([self.iconImgView pointInside:point withEvent:event]) {
//        return self.iconImgView;
//    }
//    
//    return view;
//}

@end
